package ml.evaluation;

import java.util.List;

import ml.UpAndCountDownLatch;
import weka.classifiers.functions.SMO;
import weka.classifiers.functions.supportVector.RBFKernel;
import weka.core.Instances;

public class SMOClassification extends EvaluationRunnable {
	private final double complexity;
	private final double gamma;

	public SMOClassification(UpAndCountDownLatch latch, Instances trainingData,
			Instances testData, List<EvaluationResult> results,
			double complexity, double gamma) {
		super(latch, trainingData, testData, results);
		this.complexity = complexity;
		this.gamma = gamma;
	}

	@Override
	public EvaluationResult evaluate() throws Exception {
		System.out
				.println(String
						.format("Execution of SMO (C: %f, gamma: %f) classification evaluation started ...",
								complexity, gamma));
		String options[] = { "-C", String.valueOf(complexity), "-L", "0.001",
				"-P", "1.0E-12", "-N", "0", "-V", "-1", "-W", "1" };
		String kernelOptions[] = { "-C", "250007", "-G", String.valueOf(gamma) };
		RBFKernel kernel = new RBFKernel();
		kernel.setOptions(kernelOptions);
		SMO smo = new SMO();
		smo.setKernel(kernel);
		smo.setOptions(options);
		return evaluateOnTestData(smo);
	}
}
